import { MissonModel } from "../Misson/missonModel"

/* 定义战争相关任务 */
export default class RoomTaskWar extends Room {
    /* 攻防一体任务主动处理 */
    public AIOA_AC():void{
        if (Game.time % 24) return
        var creepNum = 0
        for (var m of this.memory.Task['CREEP'])
        {
            if (m.Name == '攻防一体')
            {
                creepNum += 1

                    if (m.switch)
                    {
                        /* 如果是boost选项 */
                        for (var i in m.LabBind)
                        {
                            var drType = m.LabBind[i][1]
                            var thisLab = Game.getObjectById(m.LabBind[i][0]) as StructureLab
                            if (!thisLab) return
                            if (thisLab.store[drType] < 900 && !this.getMisson_S('CREEP','物流搬运','transport01'))
                            {
                                var TaskCreep:RoomTask = {} as RoomTask
                                Object.assign(TaskCreep,MissonModel['物流搬运'])
                                TaskCreep.relateCreep = ['transport01']
                                TaskCreep.disnum = 1200
                                TaskCreep.relateResource = [drType]
                                TaskCreep.disStructure = [thisLab.id]
                                TaskCreep.taskLevel = 1
                                TaskCreep.sourceStructure = [this.memory.TaskMemory.storageID as string]
                                this.mountMisson(TaskCreep)
                                return
                            }
                        }
                    }
            }
        }
        /* 控制爬虫的孵化 */
        global.DicCreepFrameControl[this.name]['ADIM'].num = creepNum
    }
    /* 拆家一体任务主动处理 */
    public DSOA_AC():void{
        if (Game.time % 24) return
        var creepNum = 0
        for (var m of this.memory.Task['CREEP'])
        {
            if (m.Name == '拆家一体')
            {
                creepNum += 1

                    if (m.switch)
                    {
                        /* 如果是boost选项 */
                        for (var i in m.LabBind)
                        {
                            var drType = m.LabBind[i][1]
                            var thisLab = Game.getObjectById(m.LabBind[i][0]) as StructureLab
                            if (!thisLab) return
                            if (thisLab.store[drType] < 900 && !this.getMisson_S('CREEP','物流搬运','transport01'))
                            {
                                var TaskCreep:RoomTask = {} as RoomTask
                                Object.assign(TaskCreep,MissonModel['物流搬运'])
                                TaskCreep.relateCreep = ['transport01']
                                TaskCreep.disnum = 1200
                                TaskCreep.relateResource = [drType]
                                TaskCreep.disStructure = [thisLab.id]
                                TaskCreep.taskLevel = 1
                                TaskCreep.sourceStructure = [this.memory.TaskMemory.storageID as string]
                                this.mountMisson(TaskCreep)
                                return
                            }
                        }
                    }
            }
        }
        /* 控制爬虫的孵化 */
        global.DicCreepFrameControl[this.name]['DSIM'].num = creepNum
    }
    /* 红球防御任务监听 */
    public DR_PAS():void{
        if (Game.time % 19) return
        for (var m of this.memory.Task['CREEP'])
        {
            var creepNum = 0
            if (m.Name == '红球防御')
            {
                creepNum += 1
                for (var i in m.LabBind)
                {
                    var drType = m.LabBind[i][1]
                    var thisLab = Game.getObjectById(m.LabBind[i][0]) as StructureLab
                    if (!thisLab) return
                    if (thisLab.store[drType] < 900 && !this.getMisson_S('CREEP','物流搬运','transport01'))
                    {
                    var TaskCreep:RoomTask = {} as RoomTask
                    Object.assign(TaskCreep,MissonModel['物流搬运'])
                    TaskCreep.relateCreep = ['transport01']
                    TaskCreep.disnum = 1200
                    TaskCreep.relateResource = [drType]
                    TaskCreep.disStructure = [thisLab.id]
                    TaskCreep.taskLevel = 1
                    TaskCreep.sourceStructure = [this.memory.TaskMemory.storageID as string]
                    this.mountMisson(TaskCreep)
                    return
                    }
                }

            }
        }
        /* 控制爬虫的孵化 */
        global.DicCreepFrameControl[this.name]['defend-red'].num = creepNum
    }
    /* 黄球拆迁任务监听 */
    public DY_PAS():void{
        if (Game.time % 9) return
        for (var m of this.memory.Task['CREEP'])
        {
            var creepNum = 0
            if (m.Name == '黄球拆迁')
            {
                creepNum += m.bindData['dismantle-yellow'].num
                for (var i in m.LabBind)
                {
                    var drType = m.LabBind[i][1]
                    var thisLab = Game.getObjectById(m.LabBind[i][0]) as StructureLab
                    if (!thisLab) return
                    if (thisLab.store[drType] < 900 && !this.getMisson_S('CREEP','物流搬运','transport01'))
                    {
                    var TaskCreep:RoomTask = {} as RoomTask
                    Object.assign(TaskCreep,MissonModel['物流搬运'])
                    TaskCreep.relateCreep = ['transport01']
                    TaskCreep.disnum = 1200
                    TaskCreep.relateResource = [drType]
                    TaskCreep.disStructure = [thisLab.id]
                    TaskCreep.taskLevel = 1
                    TaskCreep.sourceStructure = [this.memory.TaskMemory.storageID as string]
                    this.mountMisson(TaskCreep)
                    return
                    }
                }

            }
        }
        /* 控制爬虫的孵化 */
        global.DicCreepFrameControl[this.name]['dismantle-yellow'].num = creepNum
    }
}